﻿@using System.Data;

@using UtilsORM.MySqlData;
@using GatewayServer.Common;


@using UtilsBase;

@{
    ViewBag.PageTitle = "洪峰智能";

    Layout = "~/Views/Shared/PageTemplate.cshtml";
}


<script>
    $(document).ready(function () {
        //getGroup();
      
        var dstatus = '@(Model.status)';
        var gguid = '@(((iot_device)ViewData["reqDevice"]).d_group_guid)';


        $("#hid_m_guid").val('@(ViewData["m_guid"])');
        getDeviceModel();
        $("#d_code").val('@(((iot_device)ViewData["reqDevice"]).d_code)');
        //$("#hid_d_gw_d_guid").val('@(((iot_device)ViewData["reqDevice"]).d_gw_d_guid)');

        for (var i = 0; i < document.getElementById("status").options.length; i++) {
            if (document.getElementById("status").options[i].value == dstatus) {
                document.getElementById("status").options[i].selected = true;
                break;
            }
            else {
                document.getElementById("status").options[i].selected = false;
            }
        }

        if ($("#p_guid").val()==""){
            document.getElementById("butbackproduct").style.display="none";
        }
    });


    function getDeviceModel() {
        $("#m_guid").empty();
        $("#m_guid").append("<option value=''  selected='selected'>请选择</option>");
        $.post("getDeviceModel", { "flag": Math.random() }, function (result) {
            var myobj = (result.data);
            for (var i = myobj.length - 1; i >= 0; i--) {
                $("#m_guid").prepend("<option value='" + myobj[i].m_guid + "'>" + myobj[i].m_code + "-" + myobj[i].m_name + "</option>")
            }

            for (var i = 0; i < document.getElementById("m_guid").options.length; i++) {
                if (document.getElementById("m_guid").options[i].value == $("#hid_m_guid").val()) {
                    document.getElementById("m_guid").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("m_guid").options[i].selected = false;

                }
            }


        });
    }

    function changeStatus(dguid)
    {
        $.post("changeStatus", { "flag": Math.random() ,guid:dguid}, function (result) {
            var jsonresult = (result);
            if (jsonresult.respCode == "200") {
                window.location.reload();
            }
            else {
                alert(jsonresult.respMsg);
                return;
            }

        });
    }

    function del(dguid) {
         if(!confirm("确定删除吗？"))
         {
             return;
         }
        $.post("del", { "flag": Math.random(), guid: dguid }, function (result) {
            var jsonresult = (result);
            if (jsonresult.respCode == "200") {
                window.location.reload();
            }
            else {
                alert(jsonresult.respMsg);
                return;
            }

        });
    }
    


</script>
<div id="saper-container">
    <form id="searchForm" name="searchForm" action="list" method="post">
        <input type="hidden" name="p_guid" id="p_guid" value="@(((iot_product)ViewData["reqProduct"]).p_guid)" />
        <input type="hidden" name="d_gw_d_guid" id="d_gw_d_guid" value="@(ViewBag.d_gw_d_guid)" />
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>设备列表</h2>
            </div>
            <div class="subfiled-content">
                <div class="search-box clearfix">

                    <div class="kv-item clearfix">
                        <label>状态：</label>
                        <div class="kv-item-content">
                            <select id="status" name="status" style="width:130px;">
                                <option value="">全部</option>
                                <option value="0">启用</option>
                                <option value="1">禁用</option>
                            </select>
                        </div>
                    </div>
                   @* <div class="kv-item clearfix">
                        <label><span class="impInfo"></span>设备组：</label>
                        <div class="kv-item-content">
                            <select id="d_group_guid" name="d_group_guid" style="width:130px;">
                                <option value="">请选择</option>
                            </select>

                            <input type="hidden" name="hid_d_group_guid" id="hid_d_group_guid" value="" />
                        </div>
                    </div>*@
                    <div class="kv-item clearfix" >
                        <label><span class="impInfo">*</span>型号：</label>
                        <div class="kv-item-content">
                            <select id="m_guid" name="m_guid" style="width:130px;">
                                <option value="">请选择</option>
                            </select>
                            <input type="hidden" name="hid_m_guid" id="hid_m_guid" value="" />
                        </div>
                    </div>
                    <div class="kv-item clearfix">
                        <label>设备编码：</label>
                        <div class="kv-item-content">
                            <input type="text" id="d_code" value="" name="d_code" placeholder="设备编码" />
                        </div>
                    </div>
                    <div class="kv-item clearfix">
                        <label>设备名称：</label>
                        <div class="kv-item-content">
                            <input type="text" id="name" value="@Model.name" name="name" placeholder="名称" />
                        </div>
                    </div>
                    <a href="javascript:;" id="but_Search" name="but_Search" class="sapar-btn sapar-btn-recom query-btn">查询</a>
                    <a href="javascript:location.reload();" id="but_refresh" name="but_Search" class="sapar-btn sapar-btn-recom query-btn">刷新</a>

                    <a href="javascript:window.parent.location.href ='/product/list';" id="butbackproduct" name="butbackproduct" class="sapar-btn sapar-btn-recom query-btn">返回</a>
                </div>
                <!--表格开始-->
                <div class="table">
                    <!--表格操作-->
                    <div class="table-operate ue-clear">
                        <a href="edit?p_guid=@(Context.Request.Query["p_guid"])&gwdguid=@(ViewBag.d_gw_d_guid)" class="add" id="adda">添加</a>
                    </div>
                    <!--表格具体内容-->
                    <div class="table-box">
                        <table>
                            <thead>
                                <tr>
                                    @*                                        <th style="width:50px;"><input name="allbox" id="allbox" type="checkbox" value="" onclick="selectall()" /> 全选</th>
                                    *@
                                    <th>序号</th>
                                    <th>设备编号</th>

                                    <th>设备名称</th>
                                    <th>型号编码</th>
                                    <th>型号名称</th>
                                    <th>寄存器地址</th>
                                    <th>通道</th>
                                    <th>副码</th>
                                    <th>网关</th>
                                    <th>状态</th>
                                    <th>添加时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>

                                @{
                                    int rowcount = 0; string result = "";
                                }
                                @foreach (DataRow item in (ViewData["DataList"] as DataTable).Rows)
                                {
                                    rowcount = rowcount + 1;
                                    <tr @Html.Raw(rowcount % 2 == 0 ? "style='background-color:#EFF6FA';" : "") id="tr_@rowcount" onclick="selectTr('@rowcount','15','@item["d_id"]')">

                                        @*   <td>
                                    <input name="checkBox" type="checkbox" id="cb_@item["d_id"]" value="@item["d_id"]" />
                                    </td>*@
                                        <td>@(rowcount + ((int)ViewBag.PageIndex - 1) * (int)ViewBag.PageSize)</td>
                                        <td>@item["d_code"]</td>
                                        <td>@item["d_name"]</td>
                                        <td>@item["m_code"]</td>
                                        <td>@item["machine_model"]</td>
                                        <td>@item["d_register_address"]</td>
                                        <td>@item["d_channel"]</td>
                                        <td>@item["d_p_model_no"]</td>
                                        <td>@item["gwname"]-@item["onlinestate"]</td>
                                        <td>
                                            <a href="javascript:changeStatus('@(item["d_guid"])')">
                                                @(item["d_status"].ToString() == "0" ? "启用" : "禁用")
                                            </a>

                                            <a href="javascript:del('@(item["d_guid"])')">
                                                @(item["d_status"].ToString() == "0" ? "" : "删除")
                                            </a>

                                        </td>
                                        <td>@(UtilsDateTime.getFormatTime(item["d_mod_time"].ToString()))</td>
                                        <td>
                                            <a href="edit?order=upd&guid=@(item["d_guid"])&p_guid=@(((iot_product)ViewData["reqProduct"]).p_guid)&gwdguid=@(ViewBag.d_gw_d_guid)">修改</a>
                                            &nbsp;&nbsp;
                                            <a href="/DeviceParameterInit/edit?guid=@(item["d_guid"])&p_guid=@(((iot_product)ViewData["reqProduct"]).p_guid)&gwdguid=@(ViewBag.d_gw_d_guid)" target="_blank">指令调试</a>
                                        </td>
                                    </tr>
                                }
                                @if (rowcount < 1)
                                {
                                    <tr class="no-data"><td colspan="5" style="text-align:center">暂时没有数据</td></tr>
                                }
                            </tbody>
                        </table>
                        @Html.Raw(new GatewayServer.Common.PageHelper().GetPageHtml((int)ViewBag.RecordCount, (int)ViewBag.PageIndex, (int)ViewBag.PageCount))
                    </div>
                </div><!--表格结束-->
            </div>
        </div>
        <div id="saper-ft"></div>
    </form>
</div>
